#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"

/************************************************************************
Copyright (c) tiny
file            :beepApp.c
author          :tiny
version         :1.0.0
description     :beep driver test
other           :none
log             :first version 2023-03-05
*************************************************************************/

#define     BEEP_ON     1
#define     BEEP_OFF    0

int main(int argc, char *argv[])
{
    int fd,retvalue;
    char *filename;
    unsigned char databuf[1];

    if(argc != 3) {
        printf("Error Usage!\n");
        return -1;
    }

    filename = argv[1];

    fd = open(filename, O_RDWR);
    if(fd < 0) {
        printf("file %s open failed!\n", filename);
        return -1;
    }

    databuf[0] = atoi(argv[2]);

    retvalue = write(fd, databuf, sizeof(databuf));
    if(retvalue < 0) {
        printf(" beep control failed!\n");
        close(fd);
        return -1;
    }

    retvalue = close(fd);
    if(retvalue < 0) {
        printf("file %s close failed.\n", filename);
        return -1;
    }
    return 0;
}
